package threadman;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public abstract class ThreadRunner {
	
	
	public static void main(String[] args) {
		try {
			ServerSocket ss = new ServerSocket(88);
			Socket cs;
			
			
			boolean running = true;
			while(running){
				cs = ss.accept();
				ObjectInputStream ois = new ObjectInputStream(cs.getInputStream());
				ObjectOutputStream oos = new ObjectOutputStream(cs.getOutputStream());
				
				AbstractThreadRunnerWork atrw = (AbstractThreadRunnerWork)ois.readObject();
				atrw.start();
				atrw.join();
			
				
				
				oos.writeObject(atrw.getResult());
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
